// 测试数据，模拟新的数据结构
const testData = {
  detail: {
    "规则名：临时设施费费率": [
      ["false", "临时设施费费率应为3.8%，但实际为2.8%。", "C24302425203001", "项目A", "S001", "站点1"],
      ["false", "临时设施费费率0.028不等于3.8%", "C2430242520A001", "项目B", "S002", "站点2"]
    ],
    "规则名：乙供材料是否超结算价格上限": [
      ["false", "[材料名称: '标签黄底黑字']的价格(59.5)超过乙供材料清单中的价格上限(60.00)，[材料名称: '挂牌']的价格(1.95)超过乙供材料清单中的价格上限(2)。", "C24302425203001", "项目A", "S001", "站点1"],
      ["false", "需检查内容中的材料'旗形标签'的金额为1，但其在乙供材料清单中的结算价格上限为1.10，虽然低于乙供材料清单中的价格，然而需保证所有提供的材料价格不超过其对应的结算价格上限，建议检查数值确认保证合规。", "C2430242520A001", "项目B", "S002", "站点2"]
    ],
    "规则名：光时域反射仪": [
      ["false", "TXL1-006的光时域反射仪消耗量(台班)为0.05，而TXL6-005的光时域反射仪消耗量(台班)为0.01，不符合规则中要求的都是0.05", "C24302425203001", "项目A", "S001", "站点1"]
    ]
  },
  error: "历史自检失败"
};

console.log("测试数据:", JSON.stringify(testData, null, 2));

// 模拟rulesData计算属性的逻辑
function processRulesData(checkData) {
  if (!checkData || !checkData.detail) {
    return [];
  }
  
  const rules = [];
  const detail = checkData.detail;
  
  Object.keys(detail).forEach(key => {
    const items = detail[key];
    if (Array.isArray(items)) {
      items.forEach((item, itemIndex) => {
        if (Array.isArray(item) && item.length >= 2) {
          const resultStr = item[0];
          const reason = item[1];
          const project_id = item.length > 2 ? item[2] : null;
          const project_name = item.length > 3 ? item[3] : null;
          const site_id = item.length > 4 ? item[4] : null;
          const site_name = item.length > 5 ? item[5] : null;
          const result = resultStr === 'true' || resultStr === true;
          
          rules.push({
            rule_name: key.replace('规则名：', ''),
            result: result,
            description: '',
            reason: reason,
            project_id: project_id,
            project_name: project_name,
            site_id: site_id,
            site_name: site_name,
            details: [],
            item_index: itemIndex
          });
        }
      });
    }
  });
  
  return rules;
}

const processedRules = processRulesData(testData);
console.log("\n处理后的规则数据:", JSON.stringify(processedRules, null, 2));
console.log("\n规则数量:", processedRules.length);

// 测试分组功能
const rulesByGroup = {};
processedRules.forEach(rule => {
  if (!rulesByGroup[rule.rule_name]) {
    rulesByGroup[rule.rule_name] = [];
  }
  rulesByGroup[rule.rule_name].push(rule);
});

console.log("\n按规则名称分组:");
Object.keys(rulesByGroup).forEach(ruleName => {
  console.log(`- ${ruleName}: ${rulesByGroup[ruleName].length} 个项目`);
});